package com.fh.qqclient.service;

import com.fh.qqcommon.Message;
import com.fh.qqcommon.MessageType;

import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * @author 方小勤
 * @version 1.0~
 * 该对象，提供和消息相关的服务方法
 */
public class MessageClientService {
    public void sendMessageToALL(String content,String sendId){
        Message message = new Message();
        message.setMesType(MessageType.MESSAGE_TO_ALL_FRIEND);
        message.setSender(sendId);
        message.setContent(content);
        message.setTime(new java.util.Date().toString());
        System.out.println(sendId + " 对大家说 "+ content);
        try {
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(ManageClientConnectServerThread.getClientConnectServerThread(sendId).getSocket().getOutputStream());
            objectOutputStream.writeObject(message);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * @param content 内容
     * @param sendId 发送id
     * @param getterId 接收id
     */
    public void sendMessageToOne(String content,String sendId,String getterId) throws IOException {
        Message message = new Message();
        message.setMesType(MessageType.MESSAGE_COMM_MES_FRIEND);
        message.setSender(sendId);
        message.setReceiver(getterId);
        message.setContent(content);
        message.setTime(new java.util.Date().toString());
        System.out.println(sendId + " 对 "+ getterId+ " 说 "+ content);
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(ManageClientConnectServerThread.getClientConnectServerThread(sendId).getSocket().getOutputStream());
            objectOutputStream.writeObject(message);
    }
}
